package top.raoqq.sky.handler;

import com.alibaba.fastjson.JSONObject;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import top.raoqq.sky.constant.HttpConstant;
import top.raoqq.sky.enums.SkyResponseEnum;
import top.raoqq.sky.util.ServletUtils;
import top.raoqq.sky.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 认证失败处理器
 * @author 饶奇奇
 * @date 2023/8/8
 */
@Component
public class AuthenticationFairHandler implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException {
        String jsonStr = JSONObject.toJSONString(Result.ajax(SkyResponseEnum.NOT_AUTH));
        ServletUtils.writeJson(response, jsonStr);
    }
}
